package com.yizhuoyan.his.webapi.controller.doctor.outpatient;

import com.yizhuoyan.his.ao.DocHerbalPrescriptionAo;
import com.yizhuoyan.his.ao.DocPrescriptionAo;
import com.yizhuoyan.his.dto.DocHerbalPrescriptionDto;
import com.yizhuoyan.his.dto.JSONResponse;
import com.yizhuoyan.his.service.doctor.outpatient.PrescriptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller

@Slf4j
public class PrescriptionController {
    @Autowired
    PrescriptionService service;

    @PostMapping("/api/add/herbal-pres")
    public ResponseEntity<JSONResponse> addHerBalPrescription(DocHerbalPrescriptionAo ao)throws Exception{
        log.debug("正在添加病历号为{}的中草药处方",ao.getMedicalRecordId());
        service.addHerbalPrescription(ao);
        return ResponseEntity.ok(JSONResponse.ok());
    }

    @DeleteMapping("/api/remove/herbal-pres/{id}")
    public ResponseEntity<JSONResponse> removeHerbalPrescription(@PathVariable Long medicalId)throws Exception{
        log.debug("正在删除病历号为{}的中草药处方",medicalId);
        service.removeHerbalPrescriptionById(medicalId);
        return ResponseEntity.ok(JSONResponse.ok());
    }

    @PutMapping("/api/modify/herbal-pres/{id}")
    public ResponseEntity<JSONResponse> modifyHerbalPrescription(@PathVariable Long medicalId,DocHerbalPrescriptionAo ao)throws Exception{
        log.debug("正在修改病历号为{}的中草药处方",medicalId);
        service.modifyHerbalPrescriptionById(medicalId, ao);
        return ResponseEntity.ok(JSONResponse.ok());
    }

    @PostMapping("/api/query/herbal-pres/{id}")
    public ResponseEntity<List<JSONResponse>> queryHerbalPrescription(@PathVariable Long medicalId)throws Exception{
        log.debug("正在查询病历号为{}的中草药处方",medicalId);
        List<DocHerbalPrescriptionDto> result = service.queryHerbalPrescriptionById(medicalId);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/api/add/pres")
    public ResponseEntity<JSONResponse> addPres(DocPrescriptionAo ao)throws Exception{
        log.debug("正在添加病历号为{}的中成药处方",ao.getMedicalRecordId());
        service.addPrescription(ao);
        return ResponseEntity.ok(JSONResponse.ok());
    }

    @DeleteMapping("/api/remove/pres/{id}")
    public ResponseEntity<JSONResponse> deletePres(@PathVariable Long medicalId)throws Exception{
        log.debug("正在删除病历号为{}的中成药处方");
        service.removePrescriptionById(medicalId);
        return ResponseEntity.ok(JSONResponse.ok());
    }

    @PutMapping("/api/modify/pres/{id}")
    public ResponseEntity<JSONResponse> modifyPres(@PathVariable Long medicalId,DocPrescriptionAo ao)throws Exception{
        log.debug("正在修改病历号为{}的中成药处方",medicalId);
        service.modifyPrescriptionById(medicalId,ao);
        return ResponseEntity.ok(JSONResponse.ok());
    }

    @PostMapping("/api/query/pres/{id}")
    public ResponseEntity<JSONResponse> queryPres(@PathVariable Long medicalId)throws Exception{
        log.debug("正在查询病历号为{}的中成药处方",medicalId);
        service.queryPrescriptionByIdById(medicalId);
        return ResponseEntity.ok().build();
    }
}
